/**
 *
 * @author 
 *
 */
class MapManager extends egret.EventDispatcher {
    private static _i: MapManager;
    public static get i(): MapManager {
        if(!this._i)
            this._i = new MapManager();
            return this._i;
        }
	public constructor() {
    	super();
	}
    public restart() {
    }
    
    
    private objCon: egret.DisplayObjectContainer;
    public setup(obj: egret.DisplayObjectContainer): void {
        this.objCon = obj;
        this.initView();
    }
    
    private initView(): void {
        var data = RES.getRes("level001_json");
        var Hi: number;
        for(var i in data.layers) {
            var layers = data.layers[i].data;
            for(Hi = 0;Hi < data.layers[i].height;Hi++) {
                for(var Wi: number = 0;Wi < data.layers[i].width;Wi++) {
                    var num: number = layers[Hi * data.layers[i].width + Wi];
                    var istr: String = ""
                    if(num < 100 && num > 9) {
                        istr = "0" + num;
                    }
                    else if(i < 10) {
                        istr = "00" + num;
                    }
                    else {
                        istr = "" + num;
                    }
                    var texture = RES.getRes("EK_" + istr);
                    var scaleBitmap = new egret.Bitmap(texture);
                    scaleBitmap.x = Wi * data.tilewidth;
                    scaleBitmap.y = Hi * data.tileheight;

                    this.objCon.addChild(scaleBitmap);
                }
            }
        }
        var rtt: egret.RenderTexture = new egret.RenderTexture();
        rtt.drawToTexture(this.objCon,this.objCon.getBounds());
        var bmp: egret.Bitmap = new egret.Bitmap(rtt);
        this.objCon.removeChildren();
        this.objCon.addChild(bmp);
    }
}
